package lxbAdmin.userSystem.controller;

import lxbAdmin.userSystem.common.ResponseData;
import lxbAdmin.userSystem.dto.RolePermissionDTO;
import lxbAdmin.userSystem.dto.SystemPermissionDTO;
import lxbAdmin.userSystem.server.SystemPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/permission")
public class SystemPermissionController {


    @Autowired
    private SystemPermissionService systemPermissionService;

    /**
     * 获取当前角色的权限数据
     *
     * @param roleId
     * @return
     */
    @GetMapping("/detail")
    public ResponseData detail(@RequestParam("roleId") String roleId) {
        return ResponseData.success(systemPermissionService.detail(roleId));
    }

    /**
     * 修改当前角色的权限数据
     *
     * @param systemPermissionDTO
     * @return
     */
    @PostMapping("/edit")
    public ResponseData edit(@RequestBody SystemPermissionDTO systemPermissionDTO) {
        systemPermissionService.edit(systemPermissionDTO);
        return ResponseData.editSuccess(systemPermissionDTO.getRoleId());
    }


    /**
     * 查询权限管理的角色列表
     *
     * @param rolePermissionDTO
     * @return
     */
    @PostMapping("/all")
    public ResponseData getAll(@RequestBody RolePermissionDTO rolePermissionDTO) {
        return ResponseData.success(systemPermissionService.getAll(rolePermissionDTO));
    }
}
